//202302104030-王桉锦
package src.main.java.cn.edu.sdjzu.xg.eagle.controller;

import src.main.java.cn.edu.sdjzu.xg.eagle.dao.StudentDao;
import src.main.java.cn.edu.sdjzu.xg.eagle.entity.Student;

import java.io.IOException;
import java.sql.SQLException;

public class StudentModificationCtrl {
    protected void doPost(HttpServletRequest requset, HttpServletResponse response)throws ServletException, IOException {
        String student_json= JSONUtil.getJSON(requset);
        Student studentToAdd=JSON.parseObject(student_json, Student.class) ;
        JSONObject msg =new JSONObject();
        try{
            studentService.addStudent(studentToAdd);
            msg.put("msg","增加成功");
            msg.put("code","200");
        }catch (SQLException e){
            msg.put("msg","数据库操作异常");
            msg.put("code","500");
            e.printStackTrace();
        }catch (Exception e){
            msg.put("msg","网络异常");
            msg.put("code","500");
            e.printStackTrace();
        }
        response.getWriter().print(msg.toJSONString());
    }
}
